package com.ysd.lis.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.ysd.common.Result;
import com.ysd.lis.entity.WkQualityDetailAnnex;
import com.ysd.lis.mapper.WkQualityDetailAnnexMapper;
import com.ysd.lis.service.WkQualityDetailAnnexService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 质量控制计划明细附件表 服务实现类
 * </p>
 *
 * @author LiuQi
 * @since 2024-05-17
 */
@Service
public class WkQualityDetailAnnexServiceImpl extends ServiceImpl<WkQualityDetailAnnexMapper, WkQualityDetailAnnex> implements WkQualityDetailAnnexService {


    @Autowired
    WkQualityDetailAnnexMapper wkQualityDetailAnnexMapper;

    @Override
    public Result getQualityDetailAnnexList(String detailId, String orgId) {
        LambdaUpdateWrapper<WkQualityDetailAnnex> lambdaUpdateWrapper = new LambdaUpdateWrapper<>();
        lambdaUpdateWrapper.eq(WkQualityDetailAnnex::getDelFlag, 0)
                .eq(WkQualityDetailAnnex::getDetailId,detailId)
                .eq(StrUtil.isNotEmpty(orgId), WkQualityDetailAnnex::getOrgId, orgId);
        List<WkQualityDetailAnnex> wkQualityDetailAnnexes = wkQualityDetailAnnexMapper.selectList(lambdaUpdateWrapper);
        return Result.succ(1, "查询成功！", wkQualityDetailAnnexes);
    }

    @Override
    public Result addQualityDetailAnnex(WkQualityDetailAnnex wkQualityDetailAnnex) {
        boolean save = this.save(wkQualityDetailAnnex);
        if (save) {
            return Result.succ(1, "添加成功！", save);
        } else {
            return Result.fail( "添加失败！");
        }
    }

    @Override
    public Result deleteQualityDetailAnnex(List<String> ids) {
        boolean save = this.removeByIds(ids);
        if (save) {
            return Result.succ(1, "删除成功！", save);
        } else {
            return Result.fail( "删除失败！");
        }
    }

}
